package logistics;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

public class function_show extends JFrame {
  private Image image;
    // 构造方法
	public function_show() {
		super("后勤管理系统");
		image = Toolkit.getDefaultToolkit().getImage("src/c.jpg");
		init();
		registerListener();
		this.setResizable(false);
//		this.setExtendedState(MAXIMIZED_BOTH );//水平方向和数值方向都最大化
	}

	// 功能界面
	private JTabbedPane tabbedPane;
	private TextField tv_area = null;
	private JMenuBar mb = null;// 菜单栏
	private JMenu m_file = null;// 文件菜单
	private JMenu m_compile = null;// 编辑菜单
	private JMenu m_look = null;// 查看菜单
	private JMenu m_navigation = null;// 导航菜单
	private JMenu m_tool = null;// 工具菜单
	private JMenu m_window = null;// window菜单
	private JMenu m_help = null;// 帮助菜单

	private JMenuItem item_new = null;// 新建菜单项
	private JMenuItem item_open = null;// 打开菜单项
	private JMenuItem item_exit = null;// 退出菜单项
	private JMenuItem item_about = null;// 关于菜单项

	// 初始化组件的方法
	private void init() {
		tabbedPane = new JTabbedPane(); // 创建选项卡面板对象
		tabbedPane.setBackground(Color.LIGHT_GRAY);
		// 创建面板 tabbedPane
		
			JPanel jp = new JPanel() {
			public void paintComponent(Graphics g) {
			super.paintComponent(g);
			ImageIcon img = new ImageIcon("src/b.jpg");
			Dimension size = this.getParent().getSize();
			g.drawImage(image, 0, 0, size.width, size.height, null);

			}
			};

		// 将标签面板加入到选项卡面板对象上
		tabbedPane.addTab("首页", null, jp, "首页");
		tabbedPane.addTab("  物资申领  ", null, new goods_apply(), "物资申领");
		tabbedPane.addTab("  用车申请  ", null, new Car(), "用车申请");
		tabbedPane.addTab("  故障报修  ", null, new Repairs(), "故障报修");
		tabbedPane.addTab("  资源分配  ", null, new ResourceAllocation(), "资源分配");
		tabbedPane.addTab("  库存管理  ", null, new invman(), "库存管理");

		// s_pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		Container container = this.getContentPane();
		container.add(tabbedPane, BorderLayout.CENTER);
		this.setSize(780, 500);

		mb = new JMenuBar();// 菜单栏
		m_file = new JMenu("文件");

		m_help = new JMenu("帮助");
		m_compile = new JMenu("编辑");
		m_look = new JMenu("查看");
		m_navigation = new JMenu("导航");
		m_tool = new JMenu("工具");
		m_window = new JMenu("Window");

		item_exit = new JMenuItem("退出");
		item_about = new JMenuItem("关于");
		item_new = new JMenuItem("新建");
		item_open = new JMenuItem("打开");

		// 给文件菜单添加菜单项
		m_file.add(item_new);
		m_file.add(item_open);
		m_file.add(item_exit);
		// 给编辑菜单添加菜单项
		m_compile.add(new JMenuItem("剪切"));
		m_compile.add(new JMenuItem("复制"));
		m_compile.add(new JMenuItem("粘贴"));
		m_compile.add(new JMenuItem("删除"));
		m_compile.add(new JMenuItem("查找"));
		m_compile.add(new JMenuItem("替换"));
		// 给查看菜单添加菜单项
		m_look.add(new JMenuItem("书签"));
		m_look.add(new JMenuItem("属性"));
		m_look.add(new JMenuItem("日志"));
		m_look.add(new JMenuItem("文件"));
		// 给导航菜单添加菜单项
		m_navigation.add(new JMenuItem("后退"));
		m_navigation.add(new JMenuItem("前进"));
		m_navigation.add(new JMenuItem("切换到XX书签"));
		m_navigation.add(new JMenuItem("转到上一书签"));
		m_navigation.add(new JMenuItem("转到下一书签"));
		// 给工具菜单添加菜单项
		m_tool.add(new JMenuItem("表格复制"));
		m_tool.add(new JMenuItem("表格导出"));
		m_tool.add(new JMenuItem("功能"));
		m_tool.add(new JMenuItem("首选项"));
		// 给window菜单添加菜单项
		m_window.add(new JMenuItem("切换窗口布局"));
		m_window.add(new JMenuItem("将窗口重置为出场设置"));
		m_window.add(new JMenuItem("分配文件快捷键"));
		// 给帮助菜单添加菜单项
		m_help.add(new JMenuItem("搜索"));
		m_help.add(new JMenuItem("目录"));
		m_help.add(new JMenuItem("起始页"));
		m_help.add(new JMenuItem("检查更新"));
		m_help.add(item_about);

		// 给菜单栏添加菜单
		mb.add(m_file);
		mb.add(m_compile);
		mb.add(m_look);
		mb.add(m_navigation);
		mb.add(m_tool);
		mb.add(m_window);
		mb.add(m_help);

		// 给窗体设置菜单栏
		this.setJMenuBar(mb);
		this.setVisible(true);

		// 点击关闭按钮的时候窗口会关闭
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		this.setLocation((screenSize.width - this.getWidth()) / 2, (screenSize.height - this.getHeight()) / 2);
	}

	////// 给组件进行注册事件监听器
	public void registerListener() {
		item_new.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				newFile();
			}
		});

		item_open.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				open();
			}
		});
		item_exit.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				exit();
			}
		});
		item_about.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				new ABoutDialog(function_show.this, "自定义记事本", true);// true
																	// false模式窗口或者非模式窗口s
			}
		});
	}

	// 新建文件的功能
	private void newFile() {
		if (tv_area.getText().equals("")) {
			int res = JOptionPane.showConfirmDialog(this, "是否保存", "提示信息", JOptionPane.YES_NO_OPTION);
			if (res == JOptionPane.YES_OPTION) {
				// 文件保存对话框打开
				FileDialog fd = new FileDialog(this, "保存文件", FileDialog.SAVE);
				fd.setVisible(true);
			} else {
				tv_area.setText("");
			}
		}

	}

	// 打开文件对话框来加载文件
	private void open() {
		FileDialog fd = new FileDialog(this, "打开文件", FileDialog.LOAD);
		fd.setVisible(true);

	}

	// 退出记事本窗口程序
	private void exit() {
		newFile();
		System.exit(0);

	}

	class ABoutDialog extends JDialog {
		public JLabel desc = null;
		public JButton btn = null;
		private JPanel panel = null;

		public ABoutDialog(Frame owner, String title, boolean modal) {
			super(owner, title, modal);
			init();
		}

		private void init() {
			desc = new JLabel();
			panel = new JPanel();
			desc.setText("<html>这是一个第一次开发，开发初期阶段，还得</br>请各位多多关照！<html>");
			btn = new JButton("ok");
			btn.addActionListener(new ActionListener() {

				@Override
				public void actionPerformed(ActionEvent e) {
					ABoutDialog.this.dispose();// 关闭对话框
				}
			});
			panel.add(btn);
			getContentPane().add(desc, BorderLayout.CENTER);
			getContentPane().add(panel, BorderLayout.SOUTH);

			Toolkit kit = Toolkit.getDefaultToolkit();
			Dimension screenSize = kit.getScreenSize();
			this.setSize(300, 200);
			this.setLocation((screenSize.width - this.getWidth()) / 2, (screenSize.height - this.getHeight()) / 2);
			this.setVisible(true);

		}
	}
}